package com.taxi.driver.module.recruit;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.taxi.driver.R;
import com.taxi.driver.common.BaseActivity;
import com.taxi.driver.module.recruit.selectcar.SelectCarModleActivity;
import com.taxi.driver.module.recruit.selectcity.SelectCityActivity;
import com.taxi.driver.module.recruit.selectcolor.SelectColorActivity;
import com.taxi.driver.widget.dialog.TimeSelectorDialog;
import com.taxi.driver.widget.select.SmoothCheckBox;

import butterknife.BindView;
import butterknife.ButterKnife;

import static android.view.MotionEvent.ACTION_DOWN;

/**
 * 车辆信息 录入
 * Created by Curry on 2018/5/11.
 */

public class CarInfoEntryActivity extends BaseActivity implements View.OnTouchListener
{
    @BindView(R.id.checkbox)
    SmoothCheckBox checkBox;
    @BindView(R.id.tv_agree_protocol)
    TextView tv_agree;
    @BindView(R.id.et_server_city)
    MyEditText et_server_city;
    @BindView(R.id.et_car_regist_date)
    MyEditText et_car_regist_date;
    @BindView(R.id.et_car_model)
    MyEditText et_car_model;
    @BindView(R.id.et_car_color)
    MyEditText et_car_color;
    private static final String KEY_DEFAULT_CITY = "DEFAULT_CITY";
    private static final String KEY_DEFAULT_COLOR = "DEFAULT_COLOR";

    public static void startIntent(Context context,  String defaultCity) {
        Intent intent = new Intent(context, CarInfoEntryActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(KEY_DEFAULT_CITY, defaultCity);
        context.startActivity(intent);
    }
    public static void startIntent2(Context context,  String color) {
        Intent intent = new Intent(context, CarInfoEntryActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(KEY_DEFAULT_COLOR, color);
        context.startActivity(intent);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.carinfo_entry_view);
        ButterKnife.bind(this);
        initView();
        String defaultCity = getIntent().getStringExtra(KEY_DEFAULT_CITY);
        String defaultColor = getIntent().getStringExtra(KEY_DEFAULT_COLOR);

        et_server_city.setText(defaultCity);
        et_car_color.setText(defaultColor);

        checkBox.setOnCheckedChangeListener((checkBox1, isChecked) ->
        {

        });
        tv_agree.setOnClickListener(v ->
        {
//                WebActivity.actionStart(this, AppConfig.HOST + url, "用户协议");
        });


    }

    private void initView()
    {
        et_car_regist_date.setOnTouchListener(this);
        et_car_color.setOnTouchListener(this);
        et_car_model.setOnTouchListener(this);
        et_server_city.setOnTouchListener(this);
    }


    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        if (event.getAction()== ACTION_DOWN){
            switch (v.getId()){
                case R.id.et_car_color:
                    SelectColorActivity.startIntent(CarInfoEntryActivity.this);
                    break;
                case R.id.et_car_model:
                    SelectCarModleActivity.startIntent(CarInfoEntryActivity.this);
                    break;
                case R.id.et_server_city:
                    SelectCityActivity.startIntent(CarInfoEntryActivity.this);
                    break;
                case R.id.et_car_regist_date:
                    new TimeSelectorDialog(CarInfoEntryActivity.this,
                            "车辆注册日期", System.currentTimeMillis(), (year, month, day) -> et_car_regist_date.setText(year+month+day)).show();
                    break;
            }
        }

        return false;
    }
}
